package com.parkinglot.service.Impl;


import com.parkinglot.dao.AdvertDao;
import com.parkinglot.parmeter.AdvertaddParm;
import com.parkinglot.parmeter.AdvertqueryParm;
import com.parkinglot.parmeter.AdvertupdParm;
import com.parkinglot.pojo.Advert;
import com.parkinglot.service.AdvertService;
import com.parkinglot.vo.AdvertCountVo;
import com.parkinglot.vo.AdvertqueryVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * (Advert)表服务实现类
 *
 * @author makejava
 * @since 2020-11-13 15:27:15
 */
@Service("advertService")
@Slf4j
public class AdvertServiceImpl implements AdvertService {
    @Resource
    private AdvertDao advertDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Advert queryById(Integer id) {
        return this.advertDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<Advert> queryAllByLimit(int offset, int limit) {
        return this.advertDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param advert 实例对象
     * @return 实例对象
     */
    @Override
    public Advert insert(Advert advert) {
        this.advertDao.insert(advert);
        return advert;
    }

    /**
     * 修改数据
     *
     * @param advertupdParm 实例对象
     * @return 实例对象
     */
    @Override
    public int update(AdvertupdParm advertupdParm) {
       Advert advert=new Advert();
       BeanUtils.copyProperties(advertupdParm,advert);
       return this.advertDao.update(advert);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.advertDao.deleteById(id) > 0;
    }

 /*   @Override
    public int addadvert(AdvertaddParm advertaddParm, MultipartFile[] files, HttpServletRequest request) {
        int code=0;
        Advert advert=new Advert();
        try {
            BeanUtils.copyProperties(advertaddParm,advert);
            ImgUtils imgUtils=  new ImgUtils();
            List<String> imagepaths = imgUtils.getOrderDtl(files,request);
            for (String imgpath:imagepaths) {
                advert.setAdvertImgpath(imgpath);
                code=advertDao.insert(advert);
            }
        }catch (Exception e){
            log.warn("异常对象:{},异常消息:{},异常栈信息:{}", e.getClass(), e.getMessage());
            e.printStackTrace();
        }
        return code;
    }
*/

    @Override
    public int addadvert(AdvertaddParm advertaddParm) {
        Advert advert=new Advert();
        BeanUtils.copyProperties(advertaddParm,advert);
        return advertDao.insert(advert);
    }

    @Override
    public List<AdvertCountVo> countadvertnum() {

        return null;
    }

    @Override
    public List<AdvertCountVo> garageadverdjv(AdvertqueryParm advertqueryParm) {
        Advert advert=new Advert();
        List<AdvertCountVo>list=null;
        try {
            BeanUtils.copyProperties(advertqueryParm,advert);
            list=advertDao.garageadverdjv(advert);
            if(list.size()>0){
                return list;
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return Collections.emptyList();
    }

    @Override
    public List<AdvertqueryVo> advertpagerecord(AdvertqueryParm advertqueryParm) {
        Advert advert=new Advert();
        List<AdvertqueryVo>list=null;
        try {
            BeanUtils.copyProperties(advertqueryParm,advert);
           list= advertDao.advertpagerecord(advert);
           if (list.size()>0)
               return list;
        }catch (Exception e){
            e.printStackTrace();
        }
        return Collections.emptyList();
    }

    @Override
    public List<AdvertCountVo> advertweekdjv(AdvertqueryParm advertqueryParm) {
        Advert advert=new Advert();
        List<AdvertCountVo>list=null;
        try {
            BeanUtils.copyProperties(advertqueryParm,advert);
            list=advertDao.advertweekdjv(advert);
            if(list.size()>0){
                return list;
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return Collections.emptyList();
    }

    @Override
    public List<AdvertCountVo> advertmonthdjv(AdvertqueryParm advertqueryParm) {
        Advert advert=new Advert();
        List<AdvertCountVo>list=null;
        try {
            BeanUtils.copyProperties(advertqueryParm,advert);
            list=advertDao.advertmonthdjv(advert);
            if(list.size()>0){
                return list;
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return Collections.emptyList();
    }

    @Override
    public List<AdvertCountVo> allgaragezrdjv() {
        List<AdvertCountVo> list=null;
        try {
          list=  advertDao.allgaragezrdjv();
          if(list.size()>0)
              return list;
        }catch (Exception e){
            e.printStackTrace();
        }
        return Collections.emptyList();
    }

    @Override
    public List<AdvertCountVo> allgarageszdjv() {
        List<AdvertCountVo> list=null;
        try {
            list=  advertDao.allgarageszdjv();
            if(list.size()>0)
                return list;
        }catch (Exception e){
            e.printStackTrace();
        }
        return Collections.emptyList();
    }

    @Override
    public List<AdvertCountVo> allgaragesydjv() {
        List<AdvertCountVo> list=null;
        try {
            list=  advertDao.allgaragesydjv();
            if(list.size()>0)
                return list;
        }catch (Exception e){
            e.printStackTrace();
        }
        return Collections.emptyList();
    }


}